package com.hinner.controller;

import com.hinner.common.Result;
import com.hinner.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: PengFei.He
 * @Date: 2024/11/19 20:58
 * @Function:
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private JavaMailSender mailSender;

    @GetMapping("/get")
    public Result get(){
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("url","http://baidu.com");
        map.put("name","百度");
        list.add(map);
        map = new HashMap<>();
        map.put("url","http://sina.com");
        map.put("name","新浪");
        list.add(map);
        System.out.println("list====" +list);
        return Result.success(list);
    }

    /**
     * 发送邮件的接口
     * @param to 收件人邮箱
     * @param subject 邮件主题
     * @param content 邮件内容
     * @return 结果反馈
     */
    @GetMapping("/xxx")
    public String sendMail(@RequestParam String to,
                           @RequestParam String subject,
                           @RequestParam String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("1762581242@qq.com");
        message.setTo("hepengfei_work@outlook.com");
        message.setSubject("测试");
        message.setText("hello");
        mailSender.send(message);
        return "ok";

    }



    @GetMapping("/imageUrl")
    public String getImageUrl(@RequestParam String fileName) {
        // 拼接完整的图片URL
        String imageUrl = "file:../files/images/" + fileName;
        return imageUrl;
    }
}
